#include <iostream>

using namespace std;
#define int long long
signed main()
{
    int y , z; cin >> y >> z;
    int ret = 1e12 + 10;
    for(int k = 100000;k < 1000000;k ++)
    {
        int x = k * 1000000 + y;
        ret = min(ret , abs(x - z));
    }
    cout << ret << endl;
    return 0;
}